%Figure 3: class V1 and provider P4
cu = utilizationPriceUnit(4,1);
co = ondemandPriceUnit(4,1);
cr = reservationPriceUnit(4,1);

maxReserve = 100; %assume that only 100 can be reserved as max
mu = 25.5; %mean or expectation of the demand, given in the paper
s = sqrt(12); %standard deviation, given in the paper
A = cu*mu;

lengthOfXAxis = 50;
x = 1:lengthOfXAxis; %consider only 50 reserved VM
y = zeros(1,50);
for vmInReservationPhase = 1:lengthOfXAxis
    sum = 0;
    for d = vmInReservationPhase+1 : maxReserve
        sum = sum + (normcdf(d,mu,sqrt(12)) - normcdf(d-1,mu,sqrt(12)))*d;
    end
    y(vmInReservationPhase) = A + sum*(co-cu) + vmInReservationPhase*(cu-co)*(normcdf(100,mu,sqrt(12))-normcdf(vmInReservationPhase+1,mu,sqrt(12)));
end

coefficientsForPoly = polyfit(x,y,2);
fullYSecondPhase = coefficientsForPoly(1)*power(x,2) + coefficientsForPoly(2)*x + coefficientsForPoly(3);
[stableValueOfPrice sizeX] = min(fullYSecondPhase);

x1 = 1:sizeX;
yy1 = coefficientsForPoly(1)*power(x1,2) + coefficientsForPoly(2)*x1 + coefficientsForPoly(3);
x2 = 42:50;
yy2 = ones(1,9)*stableValueOfPrice;
plot(x1,yy1,x2,yy2,'red');
reservationCost = cr*x;
hold on;
plot(x,reservationCost);
hold on;
%plot(x1,yy1+x1*reservationCostUnit,x2,yy2+reservationCostUnit*x2);
yy = ones(1,50);
for r = 1:sizeX
    yy(r) = yy1(r) + x1(r)*cr;
end
for r = 1:9
    yy(x2(r)) = yy2(r) + x2(r)*cr;
end
plot(x,yy);
